package edu.cmu.cs211.exprtree.tests;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import static edu.cmu.cs211.exprtree.tests.ExpressionTestUtil.*;

public class NegationExpressionTest {

	  @Test
	  public void testCfold0()
	  {
	    cfoldtest("-(1)", "(-1)");
	    cfoldtest("-(x)", "-(x)");
	    cfoldtest("x", "x");
	  }
	  
	  @Test
	  public void testCfold4() {
		  cfoldtest("-(13-1)", "-12");
		  cfoldtest("-(-(-1))", "(-1)");
	  }
	  

		@Test
		public void evalNoVars() {
			/* Construct the variable map */
			Map<String, BigDecimal> map = new HashMap<String, BigDecimal>();
			
			/* test the evaluate function with no variables */
			ExpressionTestUtil.evaluatetest("-(5)", "-5", map);
			ExpressionTestUtil.evaluatetest("-(-5)", "5", map);
			ExpressionTestUtil.evaluatetest("-(-(-(-(7))))", "7", map);
		}
		
		@Test
		public void evalVars() {
			/* Construct the variable map (maybe we could do this dynamically in a loop for 
			 * a more "stressful" test?)
			 */
			Map<String, BigDecimal> map = new HashMap<String, BigDecimal>();
			map.put("x", new BigDecimal("7"));
			
			/* test the evalaute function with the current variable mapping */
			ExpressionTestUtil.evaluatetest("-(x)", "-7", map);
			ExpressionTestUtil.evaluatetest("-(-(x))", "7", map);
			ExpressionTestUtil.evaluatetest("-(-(-(-(-(x)))))", "-7", map);
		}
	  
}
